
package com.j2eefast.produce.pms.service;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.j2eefast.common.core.page.Query;
import com.j2eefast.common.core.utils.PageUtil;
import com.j2eefast.framework.utils.Constant;
import com.j2eefast.framework.utils.UserUtils;
import com.j2eefast.produce.pms.entity.PmsContractEntity;

import com.j2eefast.produce.pms.mapper.PmsContractMapper;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>签订合同</p>
 *
 * @author: summer
 * @date: 2021-05-29 16:47
 * @web: http://www.letukeji.cn
 * @version: 1.0.1
 */
@Service
@Transactional(readOnly = true)
public class PmsContractService extends ServiceImpl<PmsContractMapper, PmsContractEntity> {

    @Resource
    protected PmsContractMapper pmsContractMapper;


	/**
	 * 页面展示查询翻页
	 */
	public PageUtil findPage(Map<String, Object> params) {
		String firsts = (String) params.get("firsts");
		String seconds = (String) params.get("seconds");
		String projectName = (String) params.get("projectName");
		String signAddr = (String) params.get("signAddr");
		String amount = (String) params.get("amount");
		String beginTime = (String) params.get("beginTime");
		String endTime = (String) params.get("endTime");
		String projectName2 = (String) params.get("projectName2");
		String signAddr2 = (String) params.get("signAddr2");
		Page<PmsContractEntity> page = pmsContractMapper.findPage(
				new Query<PmsContractEntity>(params).getPage(),
				StrUtil.nullToDefault(firsts,""),
				StrUtil.nullToDefault(seconds,""),
				StrUtil.nullToDefault(projectName,""),
				StrUtil.nullToDefault(signAddr,""),
				StrUtil.nullToDefault(amount,""),
				StrUtil.nullToDefault(beginTime,""),
				StrUtil.nullToDefault(endTime,""),
				StrUtil.nullToDefault(projectName2,""),
				StrUtil.nullToDefault(signAddr2,""),
				(String) params.get(Constant.SQL_FILTER));
		return new PageUtil(page);
	}


    public List<PmsContractEntity> findList(Map<String, Object> params) {
        String projectName = (String) params.get("projectName");
//		String sampleType = (String) params.get("sampleType");
        List<PmsContractEntity> page = pmsContractMapper.findList(
                new Query<PmsContractEntity>(params).getPage(),
                StrUtil.nullToDefault(projectName, ""),
//				StrUtil.nullToDefault(sampleType,""),
                (String) params.get(Constant.SQL_FILTER));
        return page;
    }

    @Transactional(rollbackFor = Exception.class)
    public boolean deleteByIds(Long[] ids) {


        return pmsContractMapper.deleteByIds(ids);

    }

    @Transactional(rollbackFor = Exception.class)
    public boolean updateCheck(Long id) {
        Long userId = UserUtils.getUserInfo().getId();

        return pmsContractMapper.updateCheck(id, userId);

    }

//	public boolean saves(PmsSerialEntity pmsSerialEntity){
//		pmsSerialEntity.setCodeRule(this.formatTitle(pmsSerialEntity.getCodeRule(),pmsSerialEntity.getCurrentValue()));
//		pmsSerialEntity.setCurrentValue(1L);
//		this.save(pmsSerialEntity);
//		return false;
//	}

//	protected Map<String,String> formatTitle(Long total, Long id){
//		Map<String, String> map = new HashMap<String,String>();       //数据采用的哈希表结构
//
//		//查询工程编号
////		PmsParticipantEntity pmsParticipantEntity = pmsParticipantMapper.selectParticipant();
//		//{项目名称}项目报备申请-{创建人}（{创建时间}）
//		PmsContractEntity pmsContractEntity=pmsContractMapper.selectSerial(id);
//		String title=pmsSerialEntity.getCodeRule();
//		Date date=new Date();
////		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
//		SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHss");
//		//String date = sdf.format(new Date());
//		String dateString = formatter.format(date);
//		title =title.replace("{YMDHS}", dateString);
//
//		SimpleDateFormat formatters = new SimpleDateFormat("yyyyMMdd");
//		String dateStrings = formatters.format(date);
//		title = title.replace("{YMD}", dateStrings);
//		String total1="1";
//		if(total!=null){
//			total1 = Long.toString(total+1L);
//		}
//		title = title.replace("{序号}", total1);
//		map.put("title",title);
//		map.put("total",total1);
//		return map;
//	}

}
